<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        padding: 0;
        margin: 0;
      }

      .wrap {
        width: 300px;
        height: 350px;
        margin: 100px auto;
        /* overflow: hidden; */
        border: 2px solid #ccc;
      }

      .wrap .bg {
        width: 300px;
        height: 300px;
        background-color: #bbb;
      }

      .boxWrap {
        width: 300px;
        height: 50px;
        display: flex;
      }

      .boxWrap > button {
        width: 100px;
        height: 100%;
      }
      .bg > div {
        width: 300px;
        height: 100%;
        display: none;
      }
      .bg > div:nth-of-type(1) {
        background-color: red;
        /* display: block; */
      }
      .bg > div:nth-of-type(2) {
        background-color: blue;
      }
      .bg > div:nth-of-type(3) {
        background-color: yellow;
      }
      .Block {
        display: block !important;
      }
      /* .None {
        display: none;
      } */
    </style>
  </head>
  <body>
    <div class="wrap">
      <div class="bg">
        <div class="Block"></div>
        <div></div>
        <div></div>
      </div>
      <div class="boxWrap">
        <button>1</button>
        <button>2</button>
        <button>3</button>
      </div>
    </div>
  </body>
  <script>
    let box = document.querySelector(".wrap");
    class Tab {
      constructor(dom) {
        this.aBtn = dom.querySelectorAll("button");
        this.oDiv = dom.querySelectorAll(".bg div");
        this.init();
        // this.oDiv[0].style.display = "block";
      }
      init() {
        this.aBtn.forEach((btn, index) => {
          btn.onclick = () => {
            console.log(this);
            console.log(this.oDiv);
            this.oDiv.forEach((div) => {
              div.classList.remove("Block");
            });
            this.oDiv[index].classList.add("Block");
          };
        });
      }
    }
    let tab = new Tab(box);
  </script>
</html>
